package org.caw.hbase.test.utils;

import org.junit.Ignore;
import org.mortbay.jetty.Connector;
import org.mortbay.jetty.Server;
import org.mortbay.jetty.bio.SocketConnector;
import org.mortbay.jetty.webapp.WebAppContext;

/**
 * Jetty server for hosting CAW WS.
 * 
 * @author dino.keco
 * @version 0.1
 * @since 0.1
 */
@Ignore
public class CawJettyServer {

	private static Server server;

	public static void startup() {
		Thread t = new Thread() {
			public void run() {
				server = new Server();
				SocketConnector connector = new SocketConnector();
				connector.setPort(8080);

				server.setConnectors(new Connector[] { connector });

				WebAppContext bb = new WebAppContext();
				bb.setServer(server);
				bb.setContextPath("/");
				bb.setWar("src/main/webapp");
				bb.setClassLoader(this.getClass().getClassLoader());

				server.addHandler(bb);

				try {
					System.out.println(">>> STARTING EMBEDDED JETTY SERVER, PRESS ANY KEY TO STOP");
					server.start();
				} catch (Exception e) {
					e.printStackTrace();
					System.exit(100);
				}
			}
		};

		t.start();
		try {
			Thread.sleep(5000);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}

	public static void shutdown() {
		try {
			server.stop();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
